/*
 * Copyright 2013-2019 Xia Jun(3979434@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************************
 *                                                                                     *
 *                        Website : http://www.farsunset.com                           *
 *                                                                                     *
 ***************************************************************************************
 */
package com.farsunset.lvxin.util;


import com.farsunset.cim.sdk.server.model.Message;
import org.springframework.util.StringUtils;

public class MessageUtil {


	public static Message clone(Message msg) {
		Message m = new Message();
		m.setContent(msg.getContent());
		m.setTitle(msg.getTitle());
		m.setFormat(msg.getFormat());
		m.setReceiver(msg.getReceiver());
		m.setSender(msg.getSender());
		m.setAction(msg.getAction());
		m.setId(msg.getId());
		m.setTimestamp(msg.getTimestamp());
		m.setExtra(msg.getExtra());
		return m;
	}

	public static void cleanEmptyProperties(Message msg) {
		if (StringUtils.isEmpty(msg.getSender())){
			msg.setSender(null);
		}
		if (StringUtils.isEmpty(msg.getReceiver())){
			msg.setReceiver(null);
		}
		if (StringUtils.isEmpty(msg.getAction())){
			msg.setAction(null);
		}
		if (StringUtils.isEmpty(msg.getFormat())){
			msg.setFormat(null);
		}
		if (StringUtils.isEmpty(msg.getState())){
			msg.setState(null);
		}
	}
}
